package cn.learn.office.excel_v2.sort;


import cn.learn.office.excel_v2.ExportExcelUtil;
import cn.learn.office.excel_v2.ExportExcelVo;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import java.util.List;
import java.util.Map;

/**
 * 处理无序的hashMap集合的排序方法
 *
 * @author huangyezhan
 * @version 2.0
 * @date 2020年4月20日21:17:58
 */
@Deprecated
public class HashMapColumnSort implements HandlerColumnSort {

    /**
     * 处理自定义顺序的
     *
     * @param excelVo             Excel表格存储的数据
     * @param createStyleInstance poi的cell样式对象
     * @param sheet               poi的sheet页对象
     */
    @Override
    public void columnSort(ExportExcelVo excelVo, Sheet sheet, Map<ExportExcelVo.Position, CellStyle> createStyleInstance) {
        List columns = excelVo.getList();
        //开始导入数据开始行数号（去掉表头的行数）
        int  startRowNum = excelVo.getHeadRowNum();
        Row  row         = null;
        Cell cell        = null;
        for (int i = 0; i < columns.size(); i++) {
            row = sheet.createRow(i + startRowNum);
            //处理列
            for (int j = 0; j < excelVo.getColumnNum(); j++) {
                Map<String, Object> map = (Map<String, Object>) columns.get(i);
                Object              o   = map.get(excelVo.getHeadSort()[j]);
                cell = row.createCell(j);
                ExportExcelUtil.fillDatabyRealType(createStyleInstance, o, cell);
            }
        }
    }

}

